package com.template.ejb.service.util;

import javax.naming.InitialContext;

/**
 * 
 *
 */
public class ServiceLocator {

	private static InitialContext ctx;

	private static ServiceLocator INSTANCE;

	public static final ServiceLocator getInstance() {
		if (INSTANCE == null) {
			INSTANCE = new ServiceLocator();
		}
		return INSTANCE;
	}

	/**
	 * singleton object
	 */
	private ServiceLocator() {
		try {
			ServiceLocator.ctx = new InitialContext();
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

	/**
	 * 
	 * @param jndiName
	 * @return
	 */
	public Object lookup(String jndiName) {
		try {
			return ctx.lookup(jndiName);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}

}
